package com.lcu.student.controller;

import com.lcu.Result.Result;
import com.lcu.student.entity.Student;
import com.lcu.student.entity.Teacher;
import com.lcu.student.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * 查询所有教师，及编号
     * @return
     */
    @GetMapping("/selectTeacher")
    public Result selectTeacher(){
        return teacherService.selectTeacher();
    }

    /**
     * 带条件的分页查询
     * @param currentPage
     * @param pageSize
     * @param teacher
     * @return
     */
    @PostMapping("/selectByPage/{currentPage}/{pageSize}")
    public Result selectByPage(@PathVariable int currentPage, @PathVariable int pageSize, @RequestBody Teacher teacher){
        return teacherService.selectByPage(currentPage,pageSize,teacher);
    }

    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable int id){
        return teacherService.deleteById(id);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids){
        return teacherService.deleteByIds(ids);
    }

    /**
     * 添加数据
     * @param teacher
     * @return
     */
    @PostMapping("/addTeacher")
    public Result addTeacher(@RequestBody Teacher teacher){
        return teacherService.addTeacher(teacher);
    }

    /**
     * 修改数据
     * @param teacher
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Teacher teacher){
        return teacherService.updateById(teacher);
    }

}
